package com.kun.pay_web.controller;

import com.kun.api.IPayService;
import com.kun.pojo.domain.TradePay;
import com.kun.pojo.entity.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {

    @DubboReference
    private IPayService payService;

    @RequestMapping("/createPayment")
    public Result createPayment(@RequestBody TradePay tradePay) {
        return payService.createPayment(tradePay);
    }

    @RequestMapping("/callBackPayment")
    public Result callBackPayment(@RequestBody TradePay tradePay) {
        try {
            return payService.callbackPayment(tradePay);
        } catch (MQBrokerException | RemotingException | InterruptedException | MQClientException e) {
            throw new RuntimeException(e);
        }
    }

}
